Deal gracefully with unowned selections
authorMatthias Clasen <mclasen@redhat.com>
Tue, 1 Feb 2011 00:35:51 +0000 (19:35 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 1 Feb 2011 00:35:51 +0000 (19:35 -0500)
If a selection looses its owner without a replacement, owner is
None, which we did not handle very well.

https://bugzilla.gnome.org/show_bug.cgi?id=641042

gdk/gdkevents.c
gdk/gdkevents.h
gdk/x11/gdkdisplay-x11.c

index 66a14ec92496dc0fc066bd6f03e9dc3dbf572886..cf603492aa4d914a90df3a74dd5570d5b01ffbd0 100644 (file)
@@ -568,7 +568,9 @@ gdk_event_copy (const GdkEvent *event)
       break;
 
     case GDK_OWNER_CHANGE:
-      new_event->owner_change.owner = g_object_ref (event->owner_change.owner);
+      new_event->owner_change.owner = event->owner_change.owner;
+      if (new_event->owner_change.owner)
+        g_object_ref (new_event->owner_change.owner);
       break;
 
     default:
@@ -641,7 +643,8 @@ gdk_event_free (GdkEvent *event)
       break;
       
     case GDK_OWNER_CHANGE:
-      g_object_unref (event->owner_change.owner);
+      if (event->owner_change.owner)
+        g_object_unref (event->owner_change.owner);
       break;
 
     default:
index 4902601e3c6940dd3324a04da00765e0e64bb993..91a5c8e0a7dd2178b615048623df36ee500778ce 100644 (file)
@@ -819,15 +819,15 @@ struct _GdkEventSelection
 /**
  * GdkEventOwnerChange:
  * @type: the type of the event (%GDK_OWNER_CHANGE).
- * @window: the window which received the event.
+ * @window: the window which received the event
  * @send_event: %TRUE if the event was sent explicitly (e.g. using
- *   <function>XSendEvent</function>).
- * @owner: the new owner of the selection.
- * @reason: the reason for the ownership change as a #GdkOwnerChange value.
- * @selection: the atom identifying the selection.
- * @time: the timestamp of the event.
+ *   <function>XSendEvent</function>)
+ * @owner: the new owner of the selection, or %NULL if there is none
+ * @reason: the reason for the ownership change as a #GdkOwnerChange value
+ * @selection: the atom identifying the selection
+ * @time: the timestamp of the event
  * @selection_time: the time at which the selection ownership was taken
- *   over.
+ *   over
  *
  * Generated when the owner of a selection changes. On X11, this
  * information is only available if the X server supports the XFIXES
index 20735ccf6f0d79a958652fbc6618caea17eb4c77..23dd5677f11841fee38332626677e3180aa18aef 100644 (file)
@@ -919,8 +919,11 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
          
          event->owner_change.type = GDK_OWNER_CHANGE;
          event->owner_change.window = window;
-         event->owner_change.owner = gdk_x11_window_foreign_new_for_display (display,
-                                                                              selection_notify->owner);
+          if (selection_notify->owner != None)
+            event->owner_change.owner = gdk_x11_window_foreign_new_for_display (display,
+                                                                                selection_notify->owner);
+          else
+            event->owner_change.owner = NULL;
          event->owner_change.reason = selection_notify->subtype;
          event->owner_change.selection = 
            gdk_x11_xatom_to_atom_for_display (display,